package com.link.base.base.consumer.controller;

import com.link.base.base.consumer.model.PortalAccntTagGroup;
import com.link.base.base.consumer.service.PortalAccntTagGroupService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
/**
 * 客户标签组相关服务
 * @author  yipeng.zhu@hand-china.com
 * @date:   2018/11/2 15:42
 * @version 1.0
 */

@Controller
@RequestMapping("/link/accntTagGroup")
public class AccntTagGroupController extends BasicController<PortalAccntTagGroup> {
    @Resource
    private PortalAccntTagGroupService portalAccntTagGroupService;

    @Override
    public BasicService<PortalAccntTagGroup> getBasicService() throws Exception {
        return portalAccntTagGroupService;
    }

    @Override
    public void beforQueryExample(PortalAccntTagGroup entity, HttpServletRequest request) throws Exception {

        entity.setDataSource("CRM");
    }


    /**
     * 标签生效
     * @author      yipeng.zhu@hand-china.com
     * @param       record
     * @param       session
     * @param       request
     * @param       response
     * @exception
     * @date        2018/11/2 16:07
     * @version     1.0
     */

    @RequestMapping(value = "/groupTagApproveUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> groupTagApproveUpdate(@JsonParam PortalAccntTagGroup record, HttpSession session,
                                                     HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            portalAccntTagGroupService.groupTagApproveUpdate(record);
            result.put("newRow", portalAccntTagGroupService.queryById(record));
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     *  标签失效
     * @author  yipeng.zhu@hand-china.com
     * @param record
     * @date:   2018/11/2 16:09
     * @version 1.0
     */

    @RequestMapping(value = "/groupTagRejectUpdate", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> groupTagReject(@JsonParam PortalAccntTagGroup record, HttpSession session,
                                              HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            portalAccntTagGroupService.groupTagRejectUpdate(record);
            result.put("newRow", portalAccntTagGroupService.queryById(record));
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
